<?php
// SET ERROR REPORTING
error_reporting(E_ALL);
ini_set('display_errors', TRUE);

// DEFINE SE PAGE CONSTANT
define('PG_DEBUG', TRUE);
define('PG_PAGE', TRUE);
define('PG_ROOT', realpath(dirname(__FILE__)).'/');
define('JS_VER', '4.7');

$webroot=str_replace('\\','/','http://'.$_SERVER['HTTP_HOST']);
define('PG_URL', '/'.implode('/', array_slice(explode('/', $_SERVER['PHP_SELF']), 1, -1)));
define('PG_URL_ABSOLUTE', $webroot.PG_URL);

define('MODULE_PATH', PG_ROOT.'modules/');
define('HOMEPAGE_URL', 'homepage/default');

define('OC_RENEW_FEE', '30000');
define('OC_CREATE_FEE', '69000');
define('OC365_CREATE_FEE', '365000');
// SET INCLUDE PATH TO ROOT OF SE
//set_include_path(get_include_path() . PATH_SEPARATOR . realpath("./"));

// INCLUDE DATABASE INFORMATION
include "include/database_config.php";

// INCLUDE CACHE/SESSION
include "include/cake/config.php";
include "include/class_validate.php";
include "include/class_database.php";
include "include/class_datetime.php";
include "include/class_navigation.php";
include "include/class_user.php";
include "include/class_gold.php";
include "include/object.php";
include "include/filter/filterinput.php";
include "include/environment/uri.php";
include "include/environment/request.php";
include "include/class_variable.php";
include "include/functions_general.php";
include "include/functions_email.php";
include "include/class_theme.php";
include "include/function_menu.php";
include "include/function_system.php";
include "include/function_permission.php";
include "include/function_theme.php";
include "include/function_image.php";
include "include/function_category.php";
include "include/function_ogp.php";

include "include/function_logdb.php";

include "include/awsninja/CloudfrontImageService.php";

// INITIATE SMARTY
include "include/class_smarty.php";
$smarty =& PGSmarty::getInstance();
$smarty->assign('PG_URL', PG_URL);

// INITIATE DATABASE CONNECTION
$database =& PGDatabase::getInstance();

// SET LANGUAGE CHARSET
$database->db_set_charset('utf8');
$database->db_query("SET GLOBAL time_zone = '+0:07'");

// CREATE DATETIME CLASS
$datetime = new PGDatetime();

// SET TIMEZONE
$timezone = "Asia/Ho_Chi_Minh";
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);

// CREATE URL CLASS
$uri = PGURI::getInstance();

// ENSURE NO SQL INJECTIONS THROUGH POST OR GET ARRAYS
$_POST = security($_POST);
$_GET = security($_GET);
$_COOKIE = security($_COOKIE);

$session =& PGSession::getInstance(null, true);

if( defined('PG_SESSION_RESUME') && PG_SESSION_RESUME && isset($session_id) )
{
  $session->_userAgent = md5(env('HTTP_USER_AGENT') . Configure::read('Security.salt'));
  $session->id($session_id);
}
$session->start();

// CREATE USER OBJECT AND ATTEMPT TO LOG USER IN
$user = new PGUser();
$user->user_checkCookies();

$variable = new PGVariable();

// INIT AMAZONE CLOUDFRONT IMAGE SERVICE
$oAwsCdn = new CloudfrontImageService();

// Facebook Apps Config
$fbConfig = array();
$fbConfig['appId'] = '330831000347936';
$fbConfig['secret'] = '59191364dd9f24f3ec6081f621373571';
?>